package com.ahuan.service.Impl;

import com.ahuan.domain.Module;
import com.ahuan.mapper.RoleRightMapper;
import com.ahuan.service.RoleRightService;
import com.ahuan.utils.TreeBuilder;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class RoleRightServiceImpl implements RoleRightService {
    @Autowired
    RoleRightMapper roleRightMapper;


    @Override
    @Transactional
    public boolean saveRoleRight(String roleId, List<String> rightIds) {
        System.out.println(roleRightMapper.updateRoleRight(roleId, rightIds));
        return roleRightMapper.updateRoleRight(roleId, rightIds) >= rightIds.size();
    }

    @Override
    public List<Module> queryRoleRightTree(String roleId) {
        List<Module> modules = roleRightMapper.selectRoleRightList(roleId);
        System.out.println(modules);
        TreeBuilder treeBuilder = new TreeBuilder(modules);
        List<Module> modules1 = treeBuilder.buildTree("0");
        System.out.println(modules);
        return modules1;
    }
}
